<?php
require(dirname(__FILE__)."/"."../inc/common.inc.php");
admin(13);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<script type="text/javascript" src="js/respond.min.js"></script>
<script type="text/javascript" src="js/PIE_IE678.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="css/H-ui.css"/>
<link type="text/css" rel="stylesheet" href="css/H-ui.admin.css"/>
<link type="text/css" rel="stylesheet" href="font/font-awesome.min.css"/>
<!--[if IE 7]>
<link href="font/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<title><?=$webdb['title']?></title>
</head>
<body>
<?php
function ttre($str){
	if (!$str){
		return '0';
	}else{
		return $str;
	}
}
if ($action=='reg') {
	if (!empty($subit)){
		$i=0;
		$query1 = $db->query("select * from {$pre}menu where m_fid<>'0' order by  m_id asc");
		while($rs1 = $db->fetch_array($query1)){	
			$b='ssion'.$rs1['m_id'];
			$cc=$$b;
			$ssion[$rs1['m_id']]=ttre($cc);
			if($ssion[$rs1['m_id']]<>0){
				$i++;
				if($i=='1'){
					$ddr.=$ssion[$rs1['m_id']];
				}else{
					$ddr.=','.$ssion[$rs1['m_id']];
				}
			}
		}
		
		if (!empty($id)){
			$query = $db->query("update {$pre}admin_group set ssion='{$ddr}',title='$title',content='$content' where id='$id'");
			logo('添加分组');
			refreshto(($backurl?base64_decode($backurl):'?'),'修改成功!',0.5);
		}else{
			
			$query = $db->query("INSERT INTO {$pre}admin_group (ssion,title,content) VALUES ('$ddr','$title','$content')");
			logo('修改分组');
			refreshto(($backurl?base64_decode($backurl):'?'),'添加成功!',0.5);
			
		}		
	}	
	if (!empty($id)){
		$query = $db->query("select * from {$pre}admin_group where id='{$id}'");
		while($rs = $db->fetch_array($query)){	
			$title=$rs['title'];
			$content=$rs['content'];
			$ssion=$rs['ssion'];
		}
		$ssions = explode(",",$ssion);
	}
?>
<div class="pd-0">
  <div class="Huiform">
    <table class="table table-border table-bordered table-hover table-bg">
        <form name="zhuce12"  method="post" target="_parent" >
            <input type="hidden" name="backurl" value="<?=$backurl?>">
    <tr>
    	<td width="15%" height="25" align="right" bgcolor="#f7f7f7" class="bgcolor">组名称：</td>
      <td width="85%" height="25" bgcolor="#f7f7f7" class="bgcolor"><input type="text" name="title" class="input-text" value="<?=$title?>" /></td>
    </tr>
    
 
     <tr>
    	<td height="25" align="right" bgcolor="#f7f7f7" class="bgcolor">组权限：</td>
      <td height="25" bgcolor="#f7f7f7" class="bgcolor">
      <?php
      $query1 = $db->query("select * from {$pre}menu where m_fid='0' order by  m_id asc");
		while($rs1 = $db->fetch_array($query1)){	
	  ?>
   		<div style="height:22px; line-height:22px; color:#FF0000;">&nbsp;&nbsp;<?=$rs1['m_title']?></div>
            <div style="padding-left:30px; color:#CC6600;">
            <?php
            $query2 = $db->query("select * from {$pre}menu where m_fid='".$rs1['m_id']."' order by  m_id asc");
			while($rs2 = $db->fetch_array($query2)){	
			?>
      			<input name="ssion<?=$rs2['m_id']?>" type="checkbox" value="<?=$rs2['m_id']?>" id="chkAdv<?=$rs2['m_id']?>" <?php if(@in_array($rs2['m_id'],$ssions)){ echo 'checked'; }?> ><label for="chkAdv<?=$rs2['m_id']?>"><?=$rs2['m_title']?></label>&nbsp;
             <?php
             }
			?>
            </div>
      <?php 
	  }
	  ?>      </td>
    </tr> 
     <tr>
    	<td width="15%" height="25" align="right" bgcolor="#f7f7f7" class="bgcolor">组描述：</td>
      <td width="85%" height="25" bgcolor="#f7f7f7" class="bgcolor"><textarea name="content" class="input-text" cols="60" rows="5" ><?=$content?></textarea></td>
    </tr>
    
    <tr>
   	  <td height="25" colspan="2" align="center" bgcolor="#f7f7f7" class="bgcolor"><input class="btn btn-success radius" type="submit" name="subit" value="<?php if (!empty($id)){?>修改<?php } else{?>添加<?php }?>" /></td>
    </tr>
    </form>
    </table>
    </div>
    </div>

<?php
}else{

$grs2 = $db->get_one("select * from {$pre}admin_group where id='2'");


if($del){
	if (empty($id)){
		refreshto($FROMURL,'删除失败!',0.5);
	}
	if($id<3){
		refreshto($FROMURL,'系统组不能删除!',2);
	}else{
		$query = $db->query("DELETE FROM {$pre}admin_group WHERE id='{$id}'");
		
		$query = $db->query("update  {$pre}admin set u_group='2',u_ssion='{$grs2['ssion']}'   WHERE u_group='{$id}'");
		logo('删除分组');
		refreshto($FROMURL,'删除成功!',0.5);
	}
}
?>

<nav class="Hui-breadcrumb"><?=get_category(13)?> <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="icon-refresh"></i></a></nav>
<div class="pd-0">
  <div class="cl pd-5 bg-1 bk-gray">
    <span class="l">


        <a class="btn btn-primary radius" href="javascript:;" onClick="article_class_edit('0','1000','600','分组管理','?action=reg&backurl=<?=base64_encode($WEBURL)?>')" ><i class="icon-plus"></i> 添加分组</a>
        </span>
        <span class="r"></span>
        </div>
    <table class="table table-border table-bordered table-hover table-bg">
        <thead>
        <tr class="text-c">
            <th width="40">ID</th>
            <th width="200">角色名</th>
            <th>描述</th>
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        <?php
        $query = $db->query("select * from {$pre}admin_group  ORDER BY id asc");
        while($rs = $db->fetch_array($query)){
            ?>
            <tr class="text-c">
                <td><?=$rs['id']?></td>
                <td><?=$rs['title']?></td>
                <td><?=$rs['content']?></td>
                <td class="f-14"><a title="编辑" href="javascript:;" onClick="article_class_edit('<?=$rs['u_id']?>','1000','600','角色编辑','?action=reg&id=<?=$rs['id']?>&backurl=<?=base64_encode($WEBURL)?>')" style="text-decoration:none"><i class="icon-edit"></i></a> <a title="删除" href="?del=del&id=<?=$rs['id']?>" onClick="if(confirm('是否真的要删除本组，删除后本组管理将成为：<?=$grs2['title']?>')){location.href=''+this.href};return false;" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a></td>
            </tr>
            <?php
        }
        ?>
        </tbody>
    </table>

</div>
<?php
}
?>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="layer/layer.min.js"></script> 
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script>

</body>
</html>